from PyQt6.QtWidgets import QMainWindow, QWidget, QPushButton, QVBoxLayout, QHBoxLayout

from gui.dialogs.dialog_base64 import DialogBase64
from gui.dialogs.dialog_random_string import RandomDialog
from utils.reference import open_window, WINDOW_SET, qt_connect
from utils.settings import WINDOW_SIZE


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle('工具盒')
        self.setGeometry(100, 100, WINDOW_SIZE[0], WINDOW_SIZE[1])

        btn_random_string = QPushButton('随机', self)
        qt_connect(btn_random_string.clicked, open_window(RandomDialog))

        btn_base64 = QPushButton('Base64', self)
        qt_connect(btn_base64.clicked, open_window(DialogBase64))

        hbox1 = QHBoxLayout()
        hbox1.addWidget(btn_random_string)
        hbox1.addWidget(btn_base64)
        hbox1.addStretch(1)

        vbox = QVBoxLayout()
        vbox.addLayout(hbox1)
        vbox.addStretch(1)

        widget = QWidget(self)
        widget.setLayout(vbox)
        self.setCentralWidget(widget)

    def closeEvent(self, event):
        WINDOW_SET.clear()
